//
//  ReceiveSenCashBoxView.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/11/15.
//

import Foundation
import UIKit

class ReceiveSenCashBoxView: ElecCreateScrollView {
    let tjrqTF = DateEffect()

    let val5TF = DateEffect()
    let val6TF = CurrencyTextFieldEffect()
    let val7TF = TextFieldEffect()
//    let val8TF = SignEffect()
//    let val9TF = SignEffect()
    let val10TF = LabelEffect(withEnable: false)
    let val11TF = LabelEffect(withEnable: false)
    
    let val0TF = DateEffect()
    let val1TF = CurrencyTextFieldEffect()
    let val2TF = TextFieldEffect()
//    let val3TF = SignEffect()
//    let val4TF = SignEffect()
    let val12TF = LabelEffect(withEnable: false)
    let val13TF = LabelEffect(withEnable: false)

    func registerField(withValidator validator: Validator) {
        validator.registerField(tjrqTF.valueL, rules: [RequiredRule(message: tjrqTF.placeholder)])
//        validator.registerField(val0TF.valueL, rules: [RequiredRule(message: val0TF.placeholder)])
//        validator.registerField(val1TF.valueTF, rules: [RequiredRule(message: val1TF.placeholder)])
//        validator.registerField(val2TF.valueTF, rules: [RequiredRule(message: val2TF.placeholder)])
//        validator.registerField(val3TF, rules: [RequiredRule(message: val3TF.placeholder)])
//        validator.registerField(val4TF, rules: [RequiredRule(message: val4TF.placeholder)])
        validator.registerField(val5TF.valueL, rules: [RequiredRule(message: val5TF.placeholder)])
        validator.registerField(val6TF.valueTF, rules: [RequiredRule(message: val6TF.placeholder)])
        validator.registerField(val7TF.valueTF, rules: [RequiredRule(message: val7TF.placeholder)])
//        validator.registerField(val8TF, rules: [RequiredRule(message: val8TF.placeholder)])
//        validator.registerField(val9TF, rules: [RequiredRule(message: val9TF.placeholder)])
    }
    
    func updateHistory(withM model: StandingBookModal) {
        tjrqTF.value = Date.momentDate(model.tjrq ?? "")
        val0TF.value = model.attrValue0
        val1TF.value = model.attrValue1
        val2TF.value = model.attrValue2
//        val3TF.urlStr = model.attrValue3
//        val4TF.urlStr = model.attrValue4
        val10TF.value = model.attrValue10
        val11TF.value = model.attrValue11
        
        val5TF.value = model.attrValue5
        val6TF.value = model.attrValue6
        val7TF.value = model.attrValue7
//        val8TF.urlStr = model.attrValue8
//        val9TF.urlStr = model.attrValue9
        val12TF.value = model.attrValue12
        val13TF.value = model.attrValue13
        
//        val3TF.ctl.isHidden = true
//        val4TF.ctl.isHidden = true
//        val8TF.ctl.isHidden = true
//        val9TF.ctl.isHidden = true
//        
//        val3TF.isEdited = false
//        val4TF.isEdited = false
//        val8TF.isEdited = false
//        val9TF.isEdited = false
    }
    
    override func setupUI() {
        super.setupUI()
        
        titleL.text = "接、送库款箱记录"
        subTitleL.text = "库款箱记录"
        
        tjrqTF.placeholder = "日期"
        tjrqTF.value = Date.todayDateCN()
        tjrqTF.maximumDate = Date()
        addSubview(tjrqTF)
        tjrqTF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(subTitleL.snp.bottom).offset(18)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(56)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        noPersonBtn.setTitle("无接送库款箱记录", for: .normal)
        addSubview(noPersonBtn)
        noPersonBtn.snp.makeConstraints { (make) -> Void in
            make.centerY.equalTo(subTitleL.snp.centerY)
            make.right.equalTo(tjrqTF.snp.right)
            make.height.equalTo(30)
            make.width.equalTo(120)
        }
        
        let acceptL = UILabel()
        acceptL.font = UIFont.systemFont(ofSize: 16)
        acceptL.textColor = .hex("#E76142")
        acceptL.text = "接库"
        acceptL.textAlignment = .center
        acceptL.backgroundColor = .white
        addSubview(acceptL)
        acceptL.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(tjrqTF.snp.bottom).offset(16)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(80)
        }
        
        let acceptLine = UIView()
        acceptLine.backgroundColor = .hex("#E76142")
        insertSubview(acceptLine, belowSubview: acceptL)
        acceptLine.snp.makeConstraints { (make) -> Void in
            make.centerX.equalTo(acceptL.snp.centerX)
            make.centerY.equalTo(acceptL.snp.centerY)
            make.width.equalTo(ScreenWidth - 20)
            make.height.equalTo(0.5)
        }

        val5TF.placeholder = "接库时间"
        val5TF.dateMode = .time
        val5TF.isDarkBg = true
        addSubview(val5TF)
        val5TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(acceptLine.snp.bottom).offset(16)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val6TF.placeholder = "领解现金额(元)"
        val6TF.isDarkBg = true
        addSubview(val6TF)
        val6TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val5TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val7TF.placeholder = "款箱(只)"
        val7TF.valueTF.keyboardType = .numberPad
        val7TF.isDarkBg = true
        addSubview(val7TF)
        val7TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val6TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
//        val8TF.placeholder = "接库交接人A签名"
//        val8TF.isDarkBg = true
//        addSubview(val8TF)
//        val8TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val7TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(tjrqTF.snp.height)
//            make.width.equalTo(ScreenWidth - 20)
//        }
//        
//        val9TF.placeholder = "接库交接人B签名"
//        val9TF.isDarkBg = true
//        addSubview(val9TF)
//        val9TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val8TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(tjrqTF.snp.height)
//            make.width.equalTo(ScreenWidth - 20)
//        }
        
        val10TF.placeholder = "接库交接人A"
        val10TF.isDarkBg = true
        addSubview(val10TF)
        val10TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val7TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val11TF.placeholder = "接库交接人B"
        val11TF.isDarkBg = true
        addSubview(val11TF)
        val11TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val10TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        let sendL = UILabel()
        sendL.font = UIFont.systemFont(ofSize: 16)
        sendL.textColor = .hex("#E76142")
        sendL.text = "送库"
        sendL.textAlignment = .center
        sendL.backgroundColor = .white
        addSubview(sendL)
        sendL.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val11TF.snp.bottom).offset(16)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(80)
        }
        
        let sendLine = UIView()
        sendLine.backgroundColor = .hex("#E76142")
        insertSubview(sendLine, belowSubview: sendL)
        sendLine.snp.makeConstraints { (make) -> Void in
            make.centerX.equalTo(sendL.snp.centerX)
            make.centerY.equalTo(sendL.snp.centerY)
            make.width.equalTo(ScreenWidth - 20)
            make.height.equalTo(0.5)
        }
        
        val0TF.placeholder = "送库时间"
        val0TF.dateMode = .time
        addSubview(val0TF)
        val0TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(sendL.snp.bottom).offset(16)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val1TF.placeholder = "领解现金额(元)"
        addSubview(val1TF)
        val1TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val0TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val2TF.placeholder = "款箱(只)"
        val2TF.valueTF.keyboardType = .numberPad
        addSubview(val2TF)
        val2TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val1TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
//        val3TF.placeholder = "送库交接人A签名"
//        addSubview(val3TF)
//        val3TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val2TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(tjrqTF.snp.height)
//            make.width.equalTo(ScreenWidth - 20)
//        }
//        
//        val4TF.placeholder = "送库交接人B签名"
//        addSubview(val4TF)
//        val4TF.snp.makeConstraints { (make) -> Void in
//            make.top.equalTo(val3TF.snp.bottom).offset(10)
//            make.centerX.equalTo(self.snp.centerX)
//            make.height.equalTo(tjrqTF.snp.height)
//            make.width.equalTo(ScreenWidth - 20)
//        }
        
        val12TF.placeholder = "送库交接人A"
        addSubview(val12TF)
        val12TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val2TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        val13TF.placeholder = "送库交接人B"
        addSubview(val13TF)
        val13TF.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val12TF.snp.bottom).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.height.equalTo(tjrqTF.snp.height)
            make.width.equalTo(ScreenWidth - 20)
        }
        
        addSubview(saveBtn)
        saveBtn.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(val13TF.snp.bottom).offset(32)
            make.left.equalToSuperview().offset(10)
            make.height.equalTo(50)
            make.width.equalTo(90)
        }
        
        addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) -> Void in
            make.height.equalTo(saveBtn.snp.height)
            make.centerY.equalTo(saveBtn.snp.centerY)
            make.left.equalTo(saveBtn.snp.right).offset(10)
            make.width.equalTo(ScreenWidth - 120)
        }
        
        let bottomIV = UIImageView(image: UIImage(named: "elec_bottom"))
        addSubview(bottomIV)
        bottomIV.snp.makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo(submitBtn.snp.bottom).offset(20)
            make.bottom.equalTo(self.snp.bottom).offset(-16)
            make.height.equalTo(24)
        }
    }
}
